<?php

function smarty_function_rate( $params, Smarty &$smarty )
{
	$attrs = array( );
	$_r = '';
	
	foreach( $params as $_k => $_v )
	if( strpos( ',value,assign,append,default', $_k ) !== false )
	{
		if( strlen( $_v ) ) $$_k = $_v;
	}
	elseif( strpos( ',align,alt,class,style', $_k ) !== false  )
	{
		if( strlen( $_v ) ) $attrs[ $_k ] = $_v;
	}
	
	// attrs...
	foreach( array_keys( $attrs ) as $_k ) $attrs[$_k] = sprintf( '%s="%s"', $_k, htmlentities( $_v, ENT_QUOTES ) );
	
	// done.
	$s = join( ' ', $attrs );
	$tpl = '<img src="/img/rating1_%02d.png" width="90" height="20" %s />';
	$_r = ( is_null( $value ) )
		? ( isset( $default ) ? $default : sprintf( $tpl, 0, $s ) )
		: sprintf( $tpl, round( $value*2 )*5, $s );
	
	
	if( isset( $assign ) )
	{
		$smarty ->assign( $assign, $_r );
	}
	elseif( isset( $append ) )
	{
		$smarty ->append( $append, $_r );
	}
	else 
	{
		return $_r;
	}
    
}


?>